/* pkutil.h
 *
 * Copyright 2007-2008 OpenMoko, Inc.
 * Authored by Tick <tick@openmoko.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef __ASSASSIN_PKUTIL_H_
#define __ASSASSIN_PKUTIL_H_

#include <Ecore.h>
#include <E_DBus.h>
#include <e_dbus_proxy.h>


#define PK_DBUS_BUS 			DBUS_BUS_SYSTEM
#define PK_DBUS_SERVICE                 "org.freedesktop.PackageKit"
#define PK_DBUS_PATH                    "/org/freedesktop/PackageKit"
#define PK_DBUS_INTERFACE               "org.freedesktop.PackageKit"
#define PK_DBUS_INTERFACE_TRANSACTION   "org.freedesktop.PackageKit.Transaction"

#define TIMEOUT_THRESHOLD 900
#define KEEP_PACKAGEKIT_ALIVE_TIMEOUT 150

#define OMFILTER "none"
//#define OMFILTER "visible"


// pk_marshal_VOID__STRING_UINT_UINT_UINT_UINT				ProgressChanged
// pk_marshal_VOID__STRING_STRING					StatusChanged
// pk_marshal_VOID__STRING_STRING_UINT					Finished
// pk_marshal_VOID__STRING_STRING_STRING 				ErrorCode, RequireRestart, Message
// pk_marshal_VOID__STRING_BOOLEAN					CallerActiveChanged
// pk_marshal_VOID__STRING_STRING_STRING_STRING_STRING_STRING_UINT64	Description
// pk_marshal_VOID__STRING_STRING_STRING				Files
// pk_marshal_VOID__STRING_STRING_STRING_STRING_STRING_STRING_STRING_STRING 	Repo Signature Required
// pk_marshal_VOID__STRING_STRING_STRING_STRING				Package
// pk_marshal_VOID__STRING_STRING_STRING_BOOL				RepoDetail
// pk_marshal_VOID__STRING_STRING_STRING_STRING_STRING_STRING_STRING_STRING_STRING	UpdateDetail

#define MAX_PK_SIGNAL  16
enum _Operations_CB {
    ProgressChanged_sig = 0,
    StatusChanged_sig,
    Finished_sig,
    ErrorCode_sig,
    Message_sig,
    Details_sig,
    Files_sig,
    Package_sig,
    RepoDetail_sig,
    UpdateDetail_sig,
    END_OF_CB_SIG
};
typedef enum _Operations_CB Operations_CB;

struct __Pk_Operation {
    char * tid;
    E_DBus_Proxy *proxy;
    void *payload;
    int timestamp;
    Ecore_Timer *timer;
    E_DBus_Signal_Cb Operations[MAX_PK_SIGNAL];
};
typedef struct __Pk_Operation Pk_Operation;


Pk_Operation * pko_new();
int pko_timeout_check(Pk_Operation * pko);
int pko_timeout_cancel_transaction(void * pko);

E_DBus_Connection * pk_e_dbus_init(void);
void pk_e_dbus_shutdown(void);
E_DBus_Proxy * pk_proxy(void);
void pk_default_get_finished_cb (void *data, DBusMessage *message);

int get_pk_name_from_id (char *packageid, char *summary, char *name, int bufsize);
// Search
void pk_search_name(Pk_Operation *pko, const char *name);
void pk_search_group(Pk_Operation *pko, const char *groupname);

// Info
void pk_get_details(Pk_Operation* pko, const char * packageid);

// Action
void pk_install_package(Pk_Operation* pko, const char * packageid);
void pk_update_package(Pk_Operation * pko, const char  * packageid);
void pk_uninstall_package(Pk_Operation *pko, const char * packageid);

// System
void pk_update_system(Pk_Operation * pko);
void pk_refresh_system(Pk_Operation * pko);
void pk_get_updates(Pk_Operation * pko);

int pk_repos_ping();
#endif
